/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.yxw.yxnet_cd_center.customer_service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import com.yxw.yxnet_cd_center.common.enums.NoticeTypeEnum;
import com.yxw.yxnet_cd_center.customer_service.entity.NoticeWayEntity;
import com.yxw.yxnet_cd_center.customer_service.entity.DictValueToNoticeMessageEntity;
import com.yxw.yxnet_cd_center.customer_service.service.ICacheService;
//import com.yxw.customer_service_center.customer_service.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import com.yxw.yxnet_cd_center.customer_service.utils.RedisManager;
import com.yxw.yxnet_cd_center.customer_service.entity.YxCsNoticeEntity;
import com.yxw.yxnet_cd_center.customer_service.entity.YxCsPortEntity;
import com.yxw.yxnet_cd_center.customer_service.entity.YxCsChannelEntity;
import com.yxw.yxnet_cd_center.customer_service.entity.YxCsSmsTemplateEntity;
import com.yxw.yxnet_cd_center.customer_service.mapper.NoticeMapper;
import com.yxw.yxnet_cd_center.customer_service.mapper.SmsTemplateMapper;
import com.yxw.yxnet_cd_center.customer_service.mapper.NoticeWayMapper;
import com.yxw.yxnet_cd_center.customer_service.mapper.ChannelMapper;
import com.yxw.yxnet_cd_center.customer_service.mapper.PortMapper;
import com.yxw.yxnet_cd_center.customer_service.mapper.DictValueToNoticeMessageMapper;
//import com.yxw.customer_service_center.customer_service.entity.YxcscMqttServersClientEntity;
import java.util.List;
import java.util.Hashtable;
/**
 * @author hjx
 * @date 2023年9月26日
 * 缓存设置
 */
@Service
public class CacheService implements ICacheService{

    @Autowired
    private NoticeMapper noticeMapper;    
    @Autowired
    private RedisManager oRedisManager;
    @Autowired
    private SmsTemplateMapper oSmsTemplateMapper;    
    @Autowired
    private NoticeWayMapper oNoticeWayMapper;
    @Autowired
    private ChannelMapper oChannelMapper;
    @Autowired
    private PortMapper oPortMapper;
    @Autowired
    private DictValueToNoticeMessageMapper oDictValueToNoticeMessageMapper;
    
    private static Hashtable oCacheHashtable = new Hashtable();
    /**
     * 查询客服设定的消息
     * @param dto
     * @return
     */
    @Override    
    public YxCsNoticeEntity getSendMsgBySetting(NoticeTypeEnum oNoticeTypeEnum)
    {
        //YxCsNoticeEntity oYxCsNoticeEntity = oNoticeService.(Integer.valueOf(oNoticeTypeEnum.getCodeType()));
        QueryWrapper<DictValueToNoticeMessageEntity> oNoticeQueryWrapper = new QueryWrapper();
        oNoticeQueryWrapper.eq("project_id", oNoticeTypeEnum.getCodeType());
        DictValueToNoticeMessageEntity oDictValueToNoticeMessageEntity = oDictValueToNoticeMessageMapper.selectOne(oNoticeQueryWrapper);
        if(null != oDictValueToNoticeMessageEntity)
        {
            return oDictValueToNoticeMessageEntity.getYxCsNoticeEntity();
        }
        return null;
    }
    /*
    @Override  
    public YxCsSmsTemplateEntity getSmsTemplate(NoticeTypeEnum oNoticeTypeEnum)
    {
        QueryWrapper<YxCsSmsTemplateEntity> oSmsTemplateQueryWrapper = new QueryWrapper();
        oSmsTemplateQueryWrapper.eq("template_code", oNoticeTypeEnum.getTemplateCode());
        return oSmsTemplateMapper.selectOne(oSmsTemplateQueryWrapper);
    }
   
    @Override  
    public List<NoticeWayEntity> getNoticeWay(NoticeTypeEnum oNoticeTypeEnum)
    {
        QueryWrapper<NoticeWayEntity> oNoticeWayQueryWrapper = new QueryWrapper();
        oNoticeWayQueryWrapper.eq("project_id", oNoticeTypeEnum.getCodeType());
        return oNoticeWayMapper.selectList(oNoticeWayQueryWrapper);
    }*/
    @Override
    public YxCsChannelEntity getChannelInfor(String channelCode)
    {
        String key = "ChannelEntity_"+ channelCode;
        YxCsChannelEntity oYxCsChannelEntity = (YxCsChannelEntity)oCacheHashtable.get(key);
        if(null == oYxCsChannelEntity)
        {
            QueryWrapper<YxCsChannelEntity> oQueryWrapper = new QueryWrapper();
            oQueryWrapper.eq("channel_code", channelCode);
            oYxCsChannelEntity = oChannelMapper.selectOne(oQueryWrapper);
            if(null != oYxCsChannelEntity)
            {
                oCacheHashtable.put(key, oYxCsChannelEntity);
            }
        }
        return oYxCsChannelEntity;
    }    
    @Override  
    public YxCsPortEntity getPortInfor(String portCode)
    {
        String key = "PortEntity_"+ portCode;
        YxCsPortEntity oYxCsPortEntity = (YxCsPortEntity)oCacheHashtable.get(key);
        if(null == oYxCsPortEntity)
        {
            QueryWrapper<YxCsPortEntity> oQueryWrapper = new QueryWrapper();
            oQueryWrapper.eq("port_code", portCode);
            oYxCsPortEntity = oPortMapper.selectOne(oQueryWrapper);
            if(null != oYxCsPortEntity)
            {
                oCacheHashtable.put(key, oYxCsPortEntity);
            }
        }
        return oYxCsPortEntity;
    }

}
